/**
 * 
 */
package com.meiwenhui.sishuwujing;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.meiwenhui.sishuwujing.entities.History;

public class MyHistory extends Fragment {

	private static final String TAG = "MyHistory:Content";

	private ListView mHistorys = null;
	private List<History> histories = new ArrayList<History>(0);

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		Log.i(TAG, TAG);
		initHistory();
		View view = inflater.inflate(R.layout.activity_history, container, false);
		mHistorys = (ListView) view.findViewById(R.id.his_list);
		mHistorys.setAdapter(new HistoryAdapter(histories, inflater));

		return view;
	}

	private void initHistory() {
		for (int i = 0; i < 20; i++) {
			History history = new History();
			history.setAuthor("");
			histories.add(history);
		}
	}

	class HistoryAdapter extends BaseAdapter {

		private LayoutInflater inflater;
		private List<History> histories;

		public HistoryAdapter(List<History> histories, LayoutInflater inflater) {
			this.histories = histories;
			this.inflater = inflater;
		}

		@Override
		public int getCount() {
			return histories.size();
		}

		@Override
		public Object getItem(int i) {
			return histories.get(i);
		}

		@Override
		public long getItemId(int i) {
			return i;
		}

		@Override
		public View getView(int i, View view, ViewGroup viewgroup) {
			if (view == null) {
				view = inflater.inflate(R.layout.activity_history_listview_item, null);
			}
			TextView mTitle = (TextView) view.findViewById(R.id.his_title);
			TextView mChapter = (TextView) view.findViewById(R.id.his_chapter);
			mTitle.setText(UUID.randomUUID().toString());
			mChapter.setText(new Date().toLocaleString());
			return view;
		}

	}

}
